package com.atguigu.flink.datastream.transform;

import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * @author WEIYUNHUI
 * @date 2023/6/14 9:33
 *
 *  union合流 ： 被union的流中的数据类型必须一致。
 *
 */
public class Flink09_UnionStream {
    public static void main(String[] args) {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(1);

        DataStreamSource<Integer> ds1 = env.fromElements(1, 2, 3, 4, 5);

        DataStreamSource<Integer> ds2 = env.fromElements(6, 7, 8, 9, 10);

        DataStreamSource<String> ds3 = env.fromElements("a", "b", "c", "d", "e");

        DataStream<Integer> unionStream = ds1.union(ds2);

        unionStream.print();

        try {
            env.execute();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
